package com.neu.chenzhiping.lei;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.neu.chenzhiping.Service.dorService;
import com.neu.commons.Utils.Cover;
import com.neu.chenzhiping.Dao.dorDao;
public class dor {
    private  dorService d=null;
    public dor(){
        d=new dorService();
    }
    public boolean tianjia(Map<String,String[]> map) {
        boolean flag=false;
        Map<String,String>item=new HashMap<>();
        item=Cover.CoverToMap(map);
       int row= d.insert(item);
       if (row>0){
           flag=true;
       }
        return flag;
    }

    public String getpageNum(int pageCount){
        String pageNum="0";
        Map<String,Object>item=new HashMap<>();
        dorDao dd=new  dorDao();
        List<Map<String,Object>>list=dd.checkdor(pageCount);
        if (list.size()>0){
            item=list.get(0);
            Object p= item.get("a");
            pageNum=String.valueOf(p);
        }

        return pageNum;
    }

    public List<Map<String, Object>> findBypage(String pageIndex, int pageNum) {

        dorDao d=new dorDao();
        List<Map<String, Object>> list=new ArrayList<>();
        int a=Integer.parseInt(pageIndex);

        list=d.findpage(a,pageNum);
        return list;
    }

    public Map<String,Object> getSingle(Map<String,String[]> map) {
      List<Map<String,Object>>list=new ArrayList<>();
      Map<String,String>param=new HashMap<>();
      Map<String,Object>item=new HashMap<>();
      param=Cover.CoverToMap(map);
      dorService s=new dorService();
       list=s.findSingle(param);
       if (list.size()>0){
           item=list.get(0);
       }

      return item;


    }

    public boolean deletedor(Map<String,String[]> map) {

        boolean flag=false;
        dorService s=new dorService();
        int row=s.delete(map);
        if (row>0){
            flag=true;
        }
        return flag;
    }



}
